package gui.newgui.newtournamentwindow;

import gui.newgui.IArCompGuiComponent;
import gui.newgui.IController;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.WindowConstants;

import core.CustomIcons;
import core.GuiComponentLabels;

public class NewTournamentWindow2 extends javax.swing.JFrame implements IArCompGuiComponent {
	private final IController controller;
	private JLabel tournamentTypeLabel;
	private JLabel startdateLabel;
	private JLabel endDateLabel;
	private JLabel refereeLabel;
	private JLabel throbberLabel;
	private JButton setDateButton;
	private JButton cancelButton;
	private JButton okButton;
	private JTextField refereeTextField;
	private JTextField tournamentLeadTextField;
	private JTextField organizerTextField;
	private JTextField endDateTextField;
	private JTextField startDateTextField;
	private JTextField tournamentNameTextField;
	private JComboBox tournamentTypeDropDown;
	private JLabel tournamentLeadLabel;
	private JLabel organizerLabel;
	private JLabel tournamentNameLabel;
	JFrame parentWindow;

	public NewTournamentWindow2(JFrame startUpWindow) {
		super();
		this.parentWindow = startUpWindow;
		this.controller = new NewTournamentWindowController(this);
		this.setResizable(false);
		this.initGUI();
		((NewTournamentWindowController) this.controller).setTournementDropDownEntries();

	}

	public JLabel getTournamentTypeLabel() {
		return this.tournamentTypeLabel;
	}

	public JLabel getStartdateLabel() {
		return this.startdateLabel;
	}

	public JLabel getEndDateLabel() {
		return this.endDateLabel;
	}

	public JLabel getRefereeLabel() {
		return this.refereeLabel;
	}

	public JButton getSetDateButton() {
		return this.setDateButton;
	}

	public JButton getCancelButton() {
		return this.cancelButton;
	}

	public JButton getOkButton() {
		return this.okButton;
	}

	public JTextField getRefereeTextField() {
		return this.refereeTextField;
	}

	public JTextField getTournamentLeadTextField() {
		return this.tournamentLeadTextField;
	}

	public JTextField getOrganizerTextField() {
		return this.organizerTextField;
	}

	public JTextField getEndDateTextField() {
		return this.endDateTextField;
	}

	public JTextField getStartDateTextField() {
		return this.startDateTextField;
	}

	public JTextField getTournamentNameTextField() {
		return this.tournamentNameTextField;
	}

	public JComboBox getTournamentTypeDropDown() {
		return this.tournamentTypeDropDown;
	}

	public JLabel getTournamentLeadLabel() {
		return this.tournamentLeadLabel;
	}

	public JLabel getOrganizerLabel() {
		return this.organizerLabel;
	}

	public JLabel getTournamentNameLabel() {
		return this.tournamentNameLabel;
	}

	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout(this.getContentPane());
			this.getContentPane().setLayout(thisLayout);
			this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				this.tournamentTypeLabel = new JLabel();
				this.tournamentTypeLabel.setText(GuiComponentLabels.TOURNAMENT_TYPE);
			}
			{
				this.throbberLabel = new JLabel();
			}
			{
				this.setDateButton = new JButton();
				this.setDateButton.setIcon(CustomIcons.calendar);
				this.setDateButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						((NewTournamentWindowController) NewTournamentWindow2.this.controller).setCurrentDate();
					}
				});
			}
			{
				this.okButton = new JButton();
				this.okButton.setIcon(CustomIcons.acceptIcon);
				this.okButton.setText(GuiComponentLabels.OK_BUTTON);
				this.okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						((NewTournamentWindowController) NewTournamentWindow2.this.controller).createNewTournament();
					}
				});
			}
			{
				this.cancelButton = new JButton();
				this.cancelButton.setIcon(CustomIcons.closeIcon);
				this.cancelButton.setText(GuiComponentLabels.CANCEL_BUTTON);
				this.cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						NewTournamentWindow2.this.dispose();
					}
				});
			}
			{
				this.tournamentNameLabel = new JLabel();
				this.tournamentNameLabel.setText(GuiComponentLabels.TOURNAMENT_NAME);
			}
			{
				this.startdateLabel = new JLabel();
				this.startdateLabel.setText(GuiComponentLabels.START_DATE);
			}
			{
				this.endDateLabel = new JLabel();
				this.endDateLabel.setText(GuiComponentLabels.END_DATE);
			}
			{
				this.organizerLabel = new JLabel();
				this.organizerLabel.setText(GuiComponentLabels.ORGANIZER);
			}
			{
				this.tournamentLeadLabel = new JLabel();
				this.tournamentLeadLabel.setText(GuiComponentLabels.TOURNAMENT_LEAD);
			}
			{
				this.refereeLabel = new JLabel();
				this.refereeLabel.setText(GuiComponentLabels.REFEREE);
			}
			{
				this.refereeTextField = new JTextField();
			}
			{
				this.organizerTextField = new JTextField();
			}
			{
				this.tournamentLeadTextField = new JTextField();
			}
			{
				this.tournamentTypeDropDown = new JComboBox();
				this.tournamentTypeDropDown.setEditable(true);
			}
			{
				this.tournamentNameTextField = new JTextField();

			}
			{
				this.startDateTextField = new JTextField();
			}
			{
				this.endDateTextField = new JTextField();
			}
			thisLayout
					.setVerticalGroup(thisLayout
							.createSequentialGroup()
							.addContainerGap()
							.addGroup(
									thisLayout
											.createParallelGroup(GroupLayout.Alignment.BASELINE)
											.addComponent(this.tournamentTypeDropDown, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
													GroupLayout.PREFERRED_SIZE)
											.addComponent(this.tournamentTypeLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									thisLayout
											.createParallelGroup(GroupLayout.Alignment.BASELINE)
											.addComponent(this.tournamentNameTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
													GroupLayout.PREFERRED_SIZE)
											.addComponent(this.tournamentNameLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									thisLayout
											.createParallelGroup()
											.addGroup(
													GroupLayout.Alignment.LEADING,
													thisLayout
															.createParallelGroup(GroupLayout.Alignment.BASELINE)
															.addComponent(this.startdateLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
																	GroupLayout.PREFERRED_SIZE)
															.addComponent(this.startDateTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
																	GroupLayout.PREFERRED_SIZE))
											.addGroup(
													GroupLayout.Alignment.LEADING,
													thisLayout.createSequentialGroup().addComponent(this.setDateButton, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE)
															.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)))
							.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
											.addComponent(this.endDateTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
											.addComponent(this.endDateLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
											.addComponent(this.organizerTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
											.addComponent(this.organizerLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									thisLayout
											.createParallelGroup(GroupLayout.Alignment.BASELINE)
											.addComponent(this.tournamentLeadTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
													GroupLayout.PREFERRED_SIZE)
											.addComponent(this.tournamentLeadLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
											.addComponent(this.refereeTextField, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
											.addComponent(this.refereeLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									thisLayout
											.createParallelGroup()
											.addGroup(
													GroupLayout.Alignment.LEADING,
													thisLayout
															.createParallelGroup(GroupLayout.Alignment.BASELINE)
															.addComponent(this.okButton, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
																	GroupLayout.PREFERRED_SIZE)
															.addComponent(this.cancelButton, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
																	GroupLayout.PREFERRED_SIZE))
											.addGroup(
													thisLayout.createSequentialGroup().addComponent(this.throbberLabel, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
															.addGap(0, 0, Short.MAX_VALUE))).addContainerGap(22, 22));
			thisLayout.setHorizontalGroup(thisLayout
					.createSequentialGroup()
					.addContainerGap()
					.addGroup(
							thisLayout.createParallelGroup().addComponent(this.refereeLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
									.addComponent(this.tournamentLeadLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
									.addComponent(this.organizerLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
									.addComponent(this.endDateLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
									.addComponent(this.startdateLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
									.addComponent(this.tournamentNameLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
									.addComponent(this.tournamentTypeLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
									.addComponent(this.throbberLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE))
					.addGap(30)
					.addGroup(
							thisLayout
									.createParallelGroup()
									.addGroup(
											GroupLayout.Alignment.LEADING,
											thisLayout.createSequentialGroup().addComponent(this.okButton, GroupLayout.PREFERRED_SIZE, 122, GroupLayout.PREFERRED_SIZE).addGap(0, 45, Short.MAX_VALUE)
													.addComponent(this.cancelButton, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE))
									.addComponent(this.refereeTextField, GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
									.addComponent(this.tournamentLeadTextField, GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
									.addComponent(this.organizerTextField, GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
									.addComponent(this.endDateTextField, GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
									.addGroup(
											GroupLayout.Alignment.LEADING,
											thisLayout.createSequentialGroup().addComponent(this.startDateTextField, 0, 205, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
													.addComponent(this.setDateButton, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE))
									.addComponent(this.tournamentNameTextField, GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
									.addComponent(this.tournamentTypeDropDown, GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)).addContainerGap());
			this.pack();
			this.setSize(479, 330);
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}
	}

	public JLabel getThrobberLabel() {
		return this.throbberLabel;
	}

	@Override
	public IController getController() {
		return this.controller;
	}

	public JFrame getParentWindow() {
		return this.parentWindow;
	}

}
